<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Utils\QueryUtil;

class CreateTableAdmins extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('admins', function (Blueprint $table) {
            $table->id();
            $table->string('name', 16)->default('')->comment('管理员名称');
            $table->string('avatar', 225)->default('')->comment('头像');
            $table->string('phone', 18)->default('')->comment('手机号码');
            $table->string('password', 225)->default('')->comment('密码');
            $table->tinyInteger('type')->default(1)->comment('类型 1平台管理');
            $table->tinyInteger('enable')->default(1)->comment('状态 1正常 0禁封');
            $table->integer('role_id')->default(0)->comment('角色id');
            $table->string('tk', 225)->default('')->comment('登录token');
            $table->string('remark', 225)->default('')->comment('说明');
            $table->timestamps();

            $table->unique(['phone', 'name', 'tk']);
            $table->index('phone');
            $table->index('password');
            $table->index('type');
            $table->index('tk');
        }); QueryUtil::tableComment('admins', '管理员表');

        Schema::create('role', function (Blueprint $table) {
            $table->id();
            $table->string('name', 16)->default('')->comment('角色名称');
            $table->string('remark', 225)->default('')->comment('说明');
            $table->tinyInteger('enable')->default(1)->comment('状态 1正常 0禁封');
            $table->timestamps();

            $table->unique(['name']);
        }); QueryUtil::tableComment('role', '角色表');

        Schema::create('menus', function (Blueprint $table) {
            $table->id();
            $table->integer('pid')->default(0)->comment('父级id');
            $table->string('api', 128)->default('/')->comment('接口, "/"为菜单');
            $table->string('display_name', 128)->default('')->comment('菜单/接口名称');
            $table->string('name', 128)->default('')->comment('前端路径名称');
            $table->string('icon', 128)->default('')->comment('图标');
            $table->string('path', 128)->default('')->comment('页面路径');
            $table->tinyInteger('is_menu')->default(1)->comment('1是菜单 2不是菜单');
            $table->integer('sort')->default(500)->comment('排序');
            $table->json('param')->nullable()->comment('页面参数');
            $table->tinyInteger('has_line')->default(0)->comment('是否有下划线');
            $table->timestamps();

            $table->index('pid');
            $table->index('sort');
        }); QueryUtil::tableComment('menus', '菜单权限表');

        Schema::create('role_menu', function (Blueprint $table) {

            $table->integer('role_id')->default(0)->comment('角色id');
            $table->integer('menu_id')->default(0)->comment('权限id');

            $table->index('role_id');
            $table->index('menu_id');
        }); QueryUtil::tableComment('role_menu', '角色-菜单权限绑定表');
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('table_admins');
    }
}
